#include "mysplitter.h"

Mysplitter::Mysplitter(QWidget *parent)
    : QMainWindow(parent)
{
    setWindowTitle("分隔窗体_分割线");
    this->resize(800,600);


    QHBoxLayout* mainLayout = new QHBoxLayout(this);


    //水平分割：
    QSplitter* mainSplitter = new  QSplitter(Qt::Horizontal);


    //左边：       创建树结构
    QTreeWidget* leftWidget = new  QTreeWidget(mainSplitter);       //基于父类
    leftWidget->setColumnCount(1);
    leftWidget->setHeaderLabel("China");
    leftWidget->setRootIsDecorated(true);       //显示展开的三角形

    //创建树项目：
    QTreeWidgetItem* item1 = new QTreeWidgetItem(QStringList()<<"北京");
    QTreeWidgetItem* item2 = new QTreeWidgetItem(QStringList()<<"河南");
    QTreeWidgetItem* item3 = new QTreeWidgetItem(QStringList()<<"内蒙古");

    //把树项目添加到树结构域中：
    leftWidget->addTopLevelItem(item1);
    leftWidget->addTopLevelItem(item2);
    leftWidget->addTopLevelItem(item3);
    leftWidget->expandAll();        //展示全部；


#if 0
    //右边：       textEdit
//    QTextEdit* rightWidget = new QTextEdit(mainSplitter);
//    rightWidget->setText("中国");



    //还可以设置第三个：
//    QTableWidget* table = new QTableWidget(mainSplitter);
//    table->setColumnCount(3);
//    table->setHorizontalHeaderLabels(QStringList()<<"name"<<"age"<<"sex");

#endif

    //右边：
    QSplitter* rightSplitter = new QSplitter(Qt::Vertical,mainSplitter);
    //右上：
    QTextEdit* textEdit = new QTextEdit(rightSplitter);
    textEdit->setText("李飞");
    //右下：
    QTableWidget* table = new QTableWidget(rightSplitter);
    table->setColumnCount(3);
    table->setHorizontalHeaderLabels(QStringList()<<"name"<<"age"<<"sex");



    //设置左右比例：   1:4
    mainSplitter->setStretchFactor(0,1);
    mainSplitter->setStretchFactor(1,4);

    //设置上下比例：4:1
    rightSplitter->setStretchFactor(0,4);
    rightSplitter->setStretchFactor(1,1);

    //分割线在拖拽的时候是不是实时更新：
    mainSplitter->setOpaqueResize(true);


    mainLayout->addWidget(mainSplitter);

}

Mysplitter::~Mysplitter()
{
}

